﻿using System;
using System.Data.SqlClient;
using System.Configuration;
using MockCommon;

namespace MockDataAccess
{
    /// <summary>
    /// Summary description for Connection
    /// </summary>
    public sealed class Connection
    {
        /// <summary>
        /// Prevents a default instance of the <see cref="Connection"/> class from being created.
        /// </summary>
        private Connection()
        {
        }

        /// <summary>
        /// Retrieves the connection.
        /// </summary>
        /// <returns></returns>
        public static SqlConnection RetrieveConnection()
        {
            try
            {
                string connectionString = ConfigurationManager.ConnectionStrings["myConnection"].ConnectionString;
                SqlConnection connection = new SqlConnection(connectionString);
                return connection;
            }
            catch (ArgumentException exception)
            {
                throw new MockException(exception.Message, "MockDataAccess.GetConnection");
            }
            catch (ConfigurationErrorsException exception)
            {
                throw new MockException(exception.Message, "MockDataAccess.GetConnection");
            }
        }
    }
}
